package main

import (
	"fmt"
	"os/exec"
)

func RunGitCommand(name string, arg ...string) (string, error) {
	//gitpath := "D:\\wwwroot\\xxx"//项目地址

	cmd := exec.Command(name, arg...)
	//cmd.Dir = gitpath // 指定工作目录为git仓库目录
	//cmd.Stderr = os.Stderr
	msg, err := cmd.CombinedOutput() // 混合输出stdout+stderr
	cmd.Run()

	// 报错时 exit status 1
	fmt.Printf(string(msg))
	return string(msg), err
}

func main() {
	RunGitCommand("git", "status", "--short")
	RunGitCommand("git", "add",".")
	RunGitCommand("git", "commit","-m \"提交代码\"")
	RunGitCommand("git", "push")
}